package com.surekam.dma.web.dma.dms;
import java.util.List;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.surekam.dma.entity.dma.dms.Document;
import com.surekam.dma.service.dma.dms.DocumentManager;
import com.surekam.dma.web.CrudActionSupport;
//定义URL映射对应/demo/subject.action
@Namespace("/document")
public class DocumentAction extends CrudActionSupport<Document>{

	private static final long serialVersionUID = 1L;
	private Long id;
	private Document entity;
	private Page<Document> page = new Page<Document>(8);
	private DocumentManager documentManager;
	public void setId(Long id) {
		this.id = id;
	}
	public Document getModel() {
		return entity;
	}
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			entity=documentManager.getDoc(id);
		}else{
			entity = new Document();
		}
	}
	@Override
	public String list() throws Exception {
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		//设置默认排序方式
		if(!page.isOrderBySetted()){
			page.setOrderBy("date");
			page.setOrder(Page.ASC);
		}
		page=documentManager.searchDoc(page, filters);
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		return INPUT;
	}

	@Override
	public String save() throws Exception {
		return null;
	}

	@Override
	public String delete() throws Exception {
		return null;
	}
	@Autowired
	public void setDocManager(DocumentManager docManager) {
		this.documentManager = docManager;
	}
	public Page<Document> getPage(){
		return page;
	}
	
}
